import Vue from 'vue'
import mint from 'mint-ui'
import {Indicator} from 'mint-ui';
import {Toast} from 'mint-ui';
import {MessageBox} from 'mint-ui';
import axios from 'axios'
import 'mint-ui/lib/style.css'
import 'babel-polyfill'

import '../public/css/style-output.css'

import Router from 'vue-router';
import tool from './components/mixins/tools';

Vue.mixin(tool);
Vue.use(mint);
Vue.use(Router);

window.Indicator  = Indicator;
window.MessageBox = MessageBox;
window.Toast      = Toast;
window.axios      = axios;
window.host       = 'http://api.chebutou.com.cn';
window.cdn        = 'http://oka19npup.bkt.clouddn.com/';

function isWeixinBrowser() {
    let ua = navigator.userAgent.toLowerCase();
    return /micromessenger/.test(ua)
}


const router = new Router({
    routes: [
        {
            path: '/login',
            name: 'login',
            component: (resolve) => require(['./components/user/login.vue'], resolve),
        },
        {
            path: '/home',
            name: 'home',
            component: (resolve) => require(['./components/home/index.vue'], resolve),
            children: [
                {
                    path: 'submit',
                    name: 'submit',
                    component: (resolve) => require(['./components/home/submit.vue'], resolve),
                },
                {
                    path: 'list',
                    name: 'list',
                    component: (resolve) => require(['./components/home/list.vue'], resolve),
                },
                {
                    path: 'profile',
                    name: 'profile',
                    component: (resolve) => require(['./components/home/profile.vue'], resolve),
                },
                {
                    path: 'money',
                    name: 'money',
                    component: (resolve) => require(['./components/home/money.vue'], resolve),
                },
            ]
        },
        {
            path: '*',
            redirect: '/home/submit'
        }
    ],
    linkActiveClass: 'active'
});


const app = new Vue({
    router
}).$mount('#app');

// router.beforeEach((to, from, next) => {
//     axios.get(host + '/downstreams/heartbeat', {
//         withCredentials: true,
//         headers: {
//             'Content-Type': 'application/json',
//             'Cache-control': 'no-cache'
//         },
//     }).then(res => {
//         if (res.data.success) {
//             if (to.path != '/login') {
//                 next()
//             } else {
//                 next('/home/submit')
//             }
//         } else {
//             if (to.path == '/login') {
//                 next()
//             } else {
//                 next('/login')
//             }
//
//         }
//     })
// });

if (environment === 'dev') {
    Vue.config.devtools = true;
}

// 热重载配置
if (module.hot) {
    module.hot.accept();
}
